# <add 
# key="Sip2ConnStr" 
# value="
# Factory=InterLib;
# Domain=27.17.61.109;
# Port=2013;
# User=ACSGGHS01;Pwd=？？？？1234;
# OperID=ACSGGHS01;
# ExtNum=;
# EncodingType=0;
# Lib=011XS;
# RdrType=011XS_001;
# SndTimeout=1;
# RecvTimeout=1;
# RetryTims=3;
# "/>
import json
from sip2 import Sip2
import requests


# Make sure to .boku_config.json file in  ./Sip2, which contains the following:
# {
#     "hostName": "xxx",
#     "hostPort": xxx,
#     "User: "xxx",
#     "Pwd": "xxx",
#     "Patron": "xxx",
#     "PatronPwd": "xxx" 
# }

# Load configuration from .boku_config.json
with open('.boku_config.json', 'r') as config_file:
    config = json.load(config_file)

hostName   = config.get('hostName', '')
hostPort   = config.get('hostPort', '')
User       = config.get('User', '')
Pwd        = config.get('Pwd', '')
Patron     = config.get('Patron', '')
PatronPwd  = config.get('PatronPwd', '')


def test_sip2():
    # Create an instance of the Sip2 class
    mySip = Sip2()
    
    # Set connection parameters
    mySip.hostName = hostName
    mySip.hostPort = hostPort
    mySip.tlsEnable = False

    # Connect to the server
    mySip.connect()
    
    # # Test login request
    # login_msg = mySip.sip_login_request(User, Pwd)
    # login_response = mySip.sip_login_response(mySip.get_response(login_msg))
    # # print("Login Response:\n", login_response)
    # print("Login Response:", json.dumps(login_response, indent=2))
    # print("---------------"*5)

    
    # # Test SC status request
    # status_msg = mySip.sip_sc_status_request()
    # status_response = mySip.sip_sc_status_response(mySip.get_response(status_msg))
    # # print("SC Status Response:\n", status_response)
    # print("SC Status Response:", json.dumps(status_response, indent=2))
    # print("---------------"*5)
    
    # # Test patron information request
    # mySip.patron = Patron
    # mySip.patronpwd = PatronPwd
    # #  (none, hold, overdue, charged, fine, recall, unavail)
    # patron_info_msg = mySip.sip_patron_information_request('hold')
    # patron_info_response = mySip.sip_patron_information_response(mySip.get_response(patron_info_msg))
    # # print("Patron Information Response:\n", patron_info_response)
    # print("Patron Information Response:", json.dumps(patron_info_response, indent=2))
    # print("---------------"*5)


    # # Test patron status request
    # patron_status_msg = mySip.sip_patron_status_request()
    # patron_status_response = mySip.sip_patron_status_response(mySip.get_response(patron_status_msg))
    # # print("Patron Status Response:\n", patron_status_response)
    # print("Patron Status Response:", json.dumps(patron_status_response, indent=2))
    # print("---------------"*5)

    # Test item information request
    item_info_msg = mySip.sip_item_information_request('520000000008')  # Replace with actual item ID
    item_info_response = mySip.sip_item_information_response(mySip.get_response(item_info_msg))
    print("Item Information Response:", json.dumps(item_info_response, indent=2))
    print("---------------"*5)


    # Test renew request
    renew_msg = mySip.sip_renew_request('520000000008')  # Replace with actual item ID
    renew_response = mySip.sip_renew_response(mySip.get_response(renew_msg))
    print("Renew Response:", json.dumps(renew_response, indent=2))
    print("---------------"*5)
    
    # Disconnect from the server
    mySip.disconnect()


if __name__ == "__main__":
    test_sip2()
